Code
library(tidyverse)
library(here)
library(broom)
library(knitr)
library(kableExtra)
library(DT)
library(scales)library(tidyverse)
library(here)
library(broom)
library(knitr)
library(kableExtra)
library(DT)
library(scales)babyNames <- read_csv(here::here("supporting_artifacts", "Extended Thinking",
"Challenge 9", "StateNames_A.csv")) |>
rename(Sex = "Gender")datatable(babyNames)babyNames |>
group_by(Sex, State) |>
filter(Name == "Allison") |>
summarize(Total = sum(Count)) |>
pivot_wider(names_from = Sex, values_from = Total) |>
mutate(M = replace_na(M, 0), `F` = replace_na(`F`, 0)) |>
kable(caption = "<center><strong>Frequencies of babies named
Allison by state</strong></center>") |>
kable_styling(bootstrap_options = "striped", html_font = "Cambria") | State | F | M |
|---|---|---|
| AK | 232 | 0 |
| AL | 1535 | 0 |
| AR | 1198 | 0 |
| AZ | 1880 | 0 |
| CA | 12413 | 0 |
| CO | 1594 | 0 |
| CT | 1099 | 0 |
| DC | 321 | 0 |
| DE | 294 | 0 |
| FL | 4455 | 0 |
| GA | 3257 | 0 |
| HI | 183 | 0 |
| IA | 1477 | 0 |
| ID | 451 | 0 |
| IL | 5110 | 0 |
| IN | 3067 | 0 |
| KS | 1283 | 0 |
| KY | 1905 | 20 |
| LA | 1209 | 0 |
| MA | 2218 | 0 |
| MD | 2229 | 0 |
| ME | 340 | 0 |
| MI | 4014 | 0 |
| MN | 2374 | 0 |
| MO | 2882 | 0 |
| MS | 817 | 0 |
| MT | 226 | 0 |
| NC | 3435 | 0 |
| ND | 285 | 0 |
| NE | 807 | 0 |
| NH | 412 | 0 |
| NJ | 3052 | 0 |
| NM | 399 | 0 |
| NV | 729 | 0 |
| NY | 5747 | 0 |
| OH | 5487 | 0 |
| OK | 1421 | 0 |
| OR | 1186 | 0 |
| PA | 4307 | 0 |
| RI | 306 | 0 |
| SC | 1228 | 0 |
| SD | 376 | 0 |
| TN | 2488 | 0 |
| TX | 10192 | 0 |
| UT | 1125 | 0 |
| VA | 3220 | 0 |
| VT | 135 | 0 |
| WA | 1956 | 0 |
| WI | 2367 | 0 |
| WV | 813 | 0 |
| WY | 142 | 0 |
babyNames |>
mutate(Count = replace_na(Count, 0)) |>
group_by(Sex, State) |>
filter(Name == "Allison", Sex == "F") |>
summarize(Total = sum(Count)) |>
kable(caption = "<center><strong>Frequencies of female babies named
Allison by state</strong></center>") |>
kable_styling(bootstrap_options = "striped", html_font = "Cambria") | Sex | State | Total |
|---|---|---|
| F | AK | 232 |
| F | AL | 1535 |
| F | AR | 1198 |
| F | AZ | 1880 |
| F | CA | 12413 |
| F | CO | 1594 |
| F | CT | 1099 |
| F | DC | 321 |
| F | DE | 294 |
| F | FL | 4455 |
| F | GA | 3257 |
| F | HI | 183 |
| F | IA | 1477 |
| F | ID | 451 |
| F | IL | 5110 |
| F | IN | 3067 |
| F | KS | 1283 |
| F | KY | 1905 |
| F | LA | 1209 |
| F | MA | 2218 |
| F | MD | 2229 |
| F | ME | 340 |
| F | MI | 4014 |
| F | MN | 2374 |
| F | MO | 2882 |
| F | MS | 817 |
| F | MT | 226 |
| F | NC | 3435 |
| F | ND | 285 |
| F | NE | 807 |
| F | NH | 412 |
| F | NJ | 3052 |
| F | NM | 399 |
| F | NV | 729 |
| F | NY | 5747 |
| F | OH | 5487 |
| F | OK | 1421 |
| F | OR | 1186 |
| F | PA | 4307 |
| F | RI | 306 |
| F | SC | 1228 |
| F | SD | 376 |
| F | TN | 2488 |
| F | TX | 10192 |
| F | UT | 1125 |
| F | VA | 3220 |
| F | VT | 135 |
| F | WA | 1956 |
| F | WI | 2367 |
| F | WV | 813 |
| F | WY | 142 |
A_names <- babyNames |>
filter(Name %in% c("Alan", "Allen", "Allan"), Sex == "M")datatable(A_names)A_names |>
filter(State %in% c("CA", "PA"), Year == "2000") |>
pivot_wider(names_from = Name, values_from = Count) |>
mutate(across(Alan:Allan, .fns = replace_na, 0)) |>
rowwise() |>
mutate(Total = sum(Alan, Allen, Allan)) |>
select(-c(Year, Sex)) |>
kable(caption = "<center><strong>Total counts of Different Alan
spellings in CA and PA in 2000</strong></center>") |>
kable_styling(bootstrap_options = "striped", html_font = "Cambria") | State | Alan | Allen | Allan | Total |
|---|---|---|---|---|
| CA | 579 | 176 | 131 | 886 |
| PA | 51 | 56 | 12 | 119 |
A_names |>
filter(State %in% c("CA", "PA"), Year == "2000") |>
pivot_wider(names_from = Name, values_from = Count) |>
mutate(across(Alan:Allan, .fns = replace_na, 0)) |>
rowwise() |>
mutate(total = sum(Alan, Allen, Allan), Alan = percent(Alan/total),
Allen = percent(Allen/total),
Allan = percent(Allan/total)) |>
select(-c(total, Year, Sex)) |>
kable(caption = "<count><strong>Percentages of different Alan
spellings in CA and PA in 2000 rounded
to nearest whole number</strong></center>",
digits = 2) |>
kable_styling(bootstrap_options = "striped", html_font = "Cambria") | State | Alan | Allen | Allan |
|---|---|---|---|
| CA | 65% | 20% | 15% |
| PA | 43% | 47% | 10% |